from pyecharts.charts import Line
from pyecharts import options as opts


def DrawChart(H_Tem, L_Tem, date, day):
    # 图表对象
    Chart = Line()
    # 增加自变量坐标
    Chart.add_xaxis(date)
    Chart.add_xaxis(day)
    # 增加一条因变量数据
    Chart.add_yaxis('最高温度', H_Tem, is_smooth=True)
    # 增加一条因变量数据
    Chart.add_yaxis('最低温度', L_Tem, is_smooth=True)
    # 设置图标名称
    Chart.set_global_opts(title_opts=opts.TitleOpts(title="佛山", subtitle="7天气温走势"))
    return Chart


def Generate(dictinfo):
    # 示例数据
    Date = dictinfo['date']
    Day = dictinfo['day']
    HighlyTemperature = dictinfo['MaximumTemperature']
    LowlyTemperature = dictinfo['MinimumTemperatureDataList']

    ChartObject = DrawChart(HighlyTemperature, LowlyTemperature, Date, Day)
    ChartObject.render("WeatherReport.html")
    return


if __name__ == '__main__':
    Dictinfo = {'UpdateTime': '2020-12-26 20:48:54', 'City': '佛山', 'MaximumTemperature': ['23', '23', '24', '22', '12', '12', '14'], 'MinimumTemperatureDataList': ['16', '16', '16', '10', '5', '4', '4'], 'date': ['2020-12-26', '2020-12-27', '2020-12-28', '2020-12-29', '2020-12-30', '2020-12-31', '2021-01-01'], 'day': ['星期六', '星期日', '星期一', '星期二', '星期三', '星期四', '星期五']}

    Generate(Dictinfo)
"""
#增加平均线
Chart.add_yaxis('最高温度', H_Tem, is_smooth=True,
                    markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average")]))
#增加某节点的标记
Chart.add_yaxis('最低温度', L_Tem, is_smooth=True,
                    markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(name="自定义标记点",
                                                                               coord=[cate[2], LowlyTemperature[2]],
                                                                               value=LowlyTemperature[2])]))
"""